package be.music.tool.time;

import java.util.Observable;


public class Clock extends Observable{

	private Time time;
	
	public Clock() {
		this.time = new Time();
	}
	
	private void addSecond() {
		
		long seconds = time.getSeconds();
		
		if((seconds+1) == 60) {
			time.setSeconds(0);
			addMinute();
		}else{
			time.setSeconds(++seconds);
		}
		notifyObservers();
	}
	
	private void addMinute() {
		
		long minutes = time.getMinutes();
		
		if((minutes+1) == 60) {
			time.setMinutes(0);
			addHour();
		}else{
			time.setMinutes(++minutes);
		}
		notifyObservers();
		
	}
	
	private void addHour() {
		
		time.setHours(time.getHours()+1);
		notifyObservers();
		
	}
	
	public void tick() {
		setChanged();
		addSecond();
	}
	@Override
	public String toString() {
		return time.toString();
	}

	/**
	 * @return the time
	 */
	public Time getTime() {
		return time;
	}
	
	
	
}
